package com.tg.demo.uaa.service.impl;

import com.tg.demo.uaa.domain.Member;
import com.tg.demo.uaa.domain.MemberUserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author Rubble
 * @date 2020/8/21
 */
//@Service(value = "userDetailsService")
public class UserDetailServiceImpl implements UserDetailsService {

    @Autowired
    private BCryptPasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        // load from db
        Member member = new Member();
        member.setUsername(username);
        member.setPassword(passwordEncoder.encode("123456"));
        member.setEnabled(true);

        MemberUserDetails memberUserDetails = new MemberUserDetails(member,null);

        return memberUserDetails;
    }
}
